set(TARGET_PATH "${CMAKE_INSTALL_FULL_BINDIR}")
set(TARGET_NAME "deepin-wm-dbus")

find_package(Qt5Core REQUIRED)
find_package(Qt5DBus REQUIRED)
find_package(X11 REQUIRED)
find_package(KF5Config REQUIRED)
find_package(KF5WindowSystem REQUIRED)
find_package(KF5GlobalAccel REQUIRED)
find_package(DtkCore REQUIRED)
find_package(PkgConfig REQUIRED)

option(DISABLE_DEEPIN_WM "disable compatibility with deepin-wm" OFF)

if (DISABLE_DEEPIN_WM)
    set(DEEPIN_WM_PREFIX "<!-- By \"CONFIG+=DISABLE_DEEPIN_WM\"")
    set(DEEPIN_WM_SUFFIX "-->")
    add_definitions(-DDISABLE_DEEPIN_WM)
else()
    pkg_search_module(GSETTINGS REQUIRED gsettings-qt)
endif()

configure_file(com.deepin.wm.xml.in com.deepin.wm.xml)
configure_file(com.deepin.wm.service.in com.deepin.wm.service)

install(
    FILES
    ${CMAKE_CURRENT_BINARY_DIR}/com.deepin.wm.xml
    DESTINATION
    "${CMAKE_INSTALL_DATADIR}/dbus-1/interfaces"
)
install(
    FILES
    ${CMAKE_CURRENT_BINARY_DIR}/com.deepin.wm.service
    DESTINATION
    "${CMAKE_INSTALL_DATADIR}/dbus-1/services"
)

qt5_add_dbus_adaptor(
    wm_SRCS
    ${CMAKE_CURRENT_BINARY_DIR}/com.deepin.wm.xml
    deepinwmfaker.h
    DeepinWMFaker
)

add_executable(
    ${TARGET_NAME}
    deepinwmfaker.cpp
    main.cpp
    ${wm_SRCS}
)

target_include_directories(
    ${TARGET_NAME}
    PRIVATE
    ${GSETTINGS_INCLUDE_DIRS}
)

target_link_libraries(
    ${TARGET_NAME}
    Qt5::Core
    Qt5::DBus
    KF5::ConfigCore
    KF5::WindowSystem
    KF5::GlobalAccel
    Dtk::Core
    ${GSETTINGS_LDFLAGS}
)

install(
    TARGETS 
    ${TARGET_NAME}
    DESTINATION
    "${CMAKE_INSTALL_BINDIR}"
)
